const root = {
  val: 1,
  left: {
    val: 2,
    left: {
      val: 4
    },
    right: {
      val: 5
    }
  },
  right: {
    val: 3,
    left: {
      val: 6,
    },
    right: {
      val: 7
    }
  }
}

const postorderTraversal = (root) => {
  root.left && postorderTraversal(root.left)
  root.right && postorderTraversal(root.right)
  console.log(root?.val)
}
postorderTraversal(root)